package com.sino.androiddesign.anim.objanimator2

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint

import android.util.AttributeSet
import android.util.Log
import android.view.View


class MyView2 : View {

    private val Radius = 40f
    private var mPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)

    private var color: String? = null

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet)

    init {
        mPaint.color = Color.BLUE
    }

     fun setColor(color: String) {
        this.color = color
        // 将画笔的颜色设置成方法参数传入的颜色
        mPaint.color = Color.parseColor(color)
        // 调用了invalidate()方法,即画笔颜色每次改变都会刷新视图，然后调用onDraw()方法重新绘制圆
        // 而因为每次调用onDraw()方法时画笔的颜色都会改变,所以圆的颜色也会改变
        invalidate()
    }

    fun getColor():String{
        return this.color!!
    }

    override fun onDraw(canvas: Canvas?) {
        Log.e("111","on draw")
        canvas!!.drawCircle(40f,40f,Radius,mPaint)
    }



}